<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>

用户名： <input type="text" name="" class="userName"><br>
密码：   <input type="text" name="" class="passWord"><br>
管理员姓名 ： <input type="text" name="" class="name"><br>
权限： <select class="role">
		<option value = '1'>超级管理员</option>
		<option value = '2'>管理员</option>
		<option value = '3'>用户</option>	
	   </select> <br>
<button>提交</button>
<script type="text/javascript">
	let btn = document.querySelector('button')
	let userName = document.querySelector('.userName')
	let passWord = document.querySelector('.passWord')
	let name = document.querySelector('.name')
	let role = document.querySelector('.role')



	let role = document.querySelector('select')

	btn.onclick = function() {
		let xhr = new XMLHttpRequest()
		xhr.open('post',"http://wish.byesame.com/register")
		xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
		xhr.send(`userName=${userName.value}&passWord=${passWord.value}&name=${name.value}&role=${role.value}`)
		xhr.onreadystatechange = function() {
			if(xhr.readyState == 4){
				let res = JSON.parse(xhr.responseText)
				console.log(res)
				if(res.code == 200){
					alert('注册成功')
					//跳转地址
					// location.href = './03post.html'
				}else if(res.code == 188){
					alert('用户名重复')
				}else{
					alert('请联系管理员')
				}
			}
		}
	}
</script>
</body>
</html>